package org.cklxh.apn;

import java.net.Authenticator;
import java.net.InetSocketAddress;
import java.net.PasswordAuthentication;

public class ApnPojo {

	private Integer id;

	//Apn名称
	private String name;
	
	//Apn连接类型（cmwap、cmnet）
	private String apn;
	
	//代理IP地址及端口
	private InetSocketAddress proxyIsa;
	
	//代理身份认证
	private Authenticator proxyAi;


	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getApn() {
		return apn;
	}

	public void setApn(String apn) {
		this.apn = apn;
	}

	public InetSocketAddress getProxyIsa() {
		return proxyIsa;
	}

	public void setProxyIsa(InetSocketAddress proxyIsa) {
		this.proxyIsa = proxyIsa;
	}

	public void setProxyIsa(String proxyHost,int proxyPort){
		if(proxyHost!=null && !"".equals(proxyHost) && proxyPort!=0)
			this.proxyIsa = new InetSocketAddress(proxyHost, proxyPort);
	}
	
	
	public Authenticator getProxyAi() {
		return proxyAi;
	}

	public void setProxyAi(Authenticator proxyAi) {
		this.proxyAi = proxyAi;
	}
	
	public void setProxyAi(String username,String password) {
		this.proxyAi = new MyAuthenticator(username,password);
	}
	
	/**
	 * 身份认证内部类
	 * @author Administrator
	 */
	static class MyAuthenticator extends Authenticator {
		private String user ;
		private String password ;
		public MyAuthenticator(String user, String password) {
			this.user = user;
			this.password = password;
		}
		protected PasswordAuthentication getPasswordAuthentication() {
			return new PasswordAuthentication(user, password.toCharArray());
		}
	}
}
